package reflect;
/*
 * 调用Person类中所有被注解@AutoRunMethod标注的方法若干次
 * 次数由注解参数决定
 * */

import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;


public class Test5 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();
        Method[] methods = cls.getDeclaredMethods();
        for (Method method : methods) {
            boolean mark = method.isAnnotationPresent(AutoRunMethod.class);
            if (mark) {
                AutoRunMethod arm = method.getAnnotation(AutoRunMethod.class);
                int times = arm.value();
                for (int i = 0; i < times; i++) {
                    method.invoke(obj);
                }
            }

        }

    }
}
